package com.yanqu.road.server.cmd.estatewar.activity;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.pb.estatewar.EstateWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.palace.PalaceActivity;
import com.yanqu.road.server.manger.palace.PalaceActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_PALACE_AIDE_DISMISS, desc = "遣散幕宾")
public class PalaceAideDismissCmd extends AbstractCommand {
    private EstateWarProto.PalaceAideDismissReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = EstateWarProto.PalaceAideDismissReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        PalaceActivity palaceActivity = PalaceActivityMgr.getPalaceActivity(reqMsg.getActivityId());
        if(null == palaceActivity){
            ret = GameErrorCode.E_PALACE_ACTIVITY_NO_FOUND;
            return;
        }
        if(!SystemOpenMgr.systemOpen(player, eSystemId.PalaceActivity.getValue())){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        //发到跨服
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C_PALACE_AIDE_DISMISS, reqMsg.toBuilder());
        GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(0 != ret) {
            EstateWarProto.PalaceAideDismissRespMsg.Builder respMsg = EstateWarProto.PalaceAideDismissRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_PALACE_AIDE_DISMISS, respMsg);
        }
    }
}
